﻿using STHPMS1.DAL.D_Core;
using System.Data;
using ServiceStack.OrmLite;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore.I_DAL.Repository;
using System.Collections.Generic;

namespace STHPMS1.DAL.D_Repository
{
    public class Dp_Preventive_ModelRepository : DalBase, IDp_Preventive_ModelRepository
    {
        /// <summary>
        /// 获取预防性养护分析模型
        /// </summary>
        /// <param name="meas">养护措施</param>
        /// <param name="pci">原路面PCI</param>
        /// <param name="modelmode">模型形式</param>
        /// <returns></returns>
        public IDp_Preventive_Model GetDp_Preventive_Model(string meas, double pci, int modelmode)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "select * from DP_PREVENTIVE_MODEL where MEAS='" + meas + "' and MAXPCI>=" + pci + " and MINPCI<" + pci + " and MODELMODE=" + modelmode + "";
            return conn.Single<Dp_Preventive_Model>(strsql);
            
        }

        /// <summary>
        /// 获取预防性养护分析模型
        /// </summary>
        /// <param name="meas">养护措施</param>
        /// <param name="pci">原路面PCI</param>
        /// <param name="modelmode">模型形式</param>
        /// <returns></returns>
        public IDp_Preventive_Model GetDp_Preventive_Model(string meas, string mainsegid, int modelmode)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            string strsql = "select * from DP_PREVENTIVE_MODEL where MEAS='" + meas + "' "
                                                    + "and MAXPCI>=(select PCI from DN_DIVI_RESULT where MAINSEGID='" + mainsegid + "') "
                                                    + "and MINPCI<(select PCI from DN_DIVI_RESULT where MAINSEGID='" + mainsegid + "') and MODELMODE=" + modelmode + "";
            return conn.Single<Dp_Preventive_Model>(strsql);
            
        }
    }
}
